<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue2.4.4.js"></script>
</head>
<body>
    <div id="app">
        <input type="button" value="浪起来" @click="strMsgRun">
        <input type="button" value="别浪，低调" @click="strMsgStop">
        <p>{{msg}}</p>
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                msg: '猥琐发育，别浪~~',
                intervalId: null
            },
            methods: {
                strMsgRun: function() {
                    if (this.intervalId != null) {
                        return ;
                    }
                    var that = this; // 可以使用 `() => {}` 来保证内外的 this 的一致。
                    this.intervalId = setInterval(function(){
                        var temp = that.msg;
                        that.msg = temp.substring(1).concat(temp.charAt(0));
                    }, 200);
                },
                strMsgStop: function() {
                    if(this.intervalId) {
                        clearInterval(this.intervalId);
                        this.intervalId = null; // 重置 ， 这句很重要！
                    }
                }
            }
        });
    </script>
</body>
</html>